# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=v4l-utils
pkgver=1.28.1
pkgrel=1
pkgdesc="Userspace tools and conversion library for Video 4 Linux"
url="https://linuxtv.org/"
arch="all"
license="LGPL-2.0-or-later"
makedepends="
	alsa-lib-dev
	argp-standalone
	bash
	eudev-dev
	gettext-dev
	libintl
	libjpeg-turbo-dev
	linux-headers
	meson
	qt5-qtbase-dev
	qt5-qttools-dev
	sdl2_image-dev
	sdl2-dev
	xmlrpc-c-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-dvbv5
	libdvbv5
	ir_keytable
	$pkgname-libs
	qv4l2
	"
source="https://linuxtv.org/downloads/v4l-utils/v4l-utils-$pkgver.tar.xz
	disable-nls.patch
	ioctl-types.patch"

case "$CARCH" in
arm*|aarch64)
	# no desktop opengl on arm, only es2
	;;
*)
	subpackages="$subpackages qvidcap"
	;;
esac

build() {
	meson setup \
		--buildtype=plain \
		--prefix="/usr" \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		-Ddefault_library="both" \
	"build"

	meson compile -C "build"
}

check() {
	meson test -C "build"
}

package() {
	DESTDIR="$pkgdir" ninja -C build/ install
	install -Dm644 "$builddir"/utils/qv4l2/qv4l2.desktop \
		"$pkgdir"/usr/share/applications/qv4l2.desktop
	install -Dm644 "$builddir"/utils/qv4l2/qv4l2.svg \
		"$pkgdir"/usr/share/icons/hicolor/scalable/apps/qv4l2.svg
}

qv4l2() {
	pkgdesc="QT v4l2 test control and streaming test application"

	amove usr/bin/qv4l2 \
		usr/share
}

qvidcap() {
	pkgdesc="v4l2 video capture viewer"

	amove usr/bin/qvidcap
}

dvbv5() {
	pkgdesc="Backwards compatible DVBv5 command line utilities"

	amove usr/bin/dvb*
}

libdvbv5() {
	pkgdesc="libdvbv5 library"

	amove usr/lib/libdvbv5.*
}

libs() {
	pkgdesc="Collection of video4linux support libraries"

	amove usr/lib
}

ir_keytable() {
	pkgdesc="Alter keymaps of Remote Controller devices"

	amove usr/lib/udev \
		usr/bin/ir-keytable \
		etc/rc_maps.cfg
}

sha512sums="
6493c97f59af5fe0ffa4bb815ebac4531f5ea2b0612c2035c7f00a888ce686ee0aeeaef982553ff9ad6441c39dac63e6c718b1bedb0541cb2ce2e3c2f91ab12f  v4l-utils-1.28.1.tar.xz
028e6b51824e8be438e3c03393791ee4021ad72b2cc99d9aa8e31f53e09ea9bfc510fbfcee1b8e84ff26dc08e648d24e74dbdb7d6568f8d97fe2a2320c283f73  disable-nls.patch
b6c2c0916b2759a89b608d941b2a995ae1820de228c7acc00c3b1067c4a0d329b14bd94692e4dbe493a87a336ecc54a63a1e3784d9518d144942650f133d1676  ioctl-types.patch
"
